//
//  RKBaseController.swift
//  RKWeibo
//
//  Created by Rick on 2017/3/2.
//  Copyright © 2017年 Ricky. All rights reserved.
//

import UIKit
//MARK:-所有主控制器的基类控制器
class RKBaseController: UIViewController {

    lazy var navigationBar = UINavigationBar(frame:CGRect(x: 0, y: 0, width: UIScreen.cz_screenWidth(), height: 64))
    lazy var navItem = UINavigationItem()
    var tableView:UITableView?
    var refreshControl:UIRefreshControl?
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        loadData()
    }
    
    override var title: String?{
        didSet{
           navItem.title = title
        }
    }
    
    func loadData() -> () {
        
    }
    
}


//MARK:-设置界面
extension RKBaseController{
    func setupUI() -> () {
        view.backgroundColor = UIColor.white
        //取消自动缩进，如果隐藏了导航栏，会缩进20个点
        automaticallyAdjustsScrollViewInsets = false
        setupNavigationBar()
        setupTableView()
    }
    
    private func setupNavigationBar()->(){
        view.addSubview(navigationBar)
        navigationBar.items = [navItem]
        navigationBar.barTintColor = UIColor.cz_color(withHex: 0xF6F6F6)
        navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.darkGray]
    }
    
    private func setupTableView()->(){
        tableView = UITableView.init(frame: view.bounds, style: .plain)
        view.insertSubview(tableView!, belowSubview: navigationBar)
        tableView?.dataSource = self
        tableView?.delegate = self
        //设置内容缩进
        tableView?.contentInset = UIEdgeInsets(top: navigationBar.bounds.height, left: 0, bottom: tabBarController?.tabBar.bounds.height ?? 49, right: 0)
        
        refreshControl = UIRefreshControl()
        tableView?.addSubview(refreshControl!)
        refreshControl?.addTarget(self, action: #selector(loadData), for: .valueChanged)
    }
    
}
//MARK: - UITableViewDataSource，UITableViewDelegate
extension RKBaseController:UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
}
